package com.erp.order.purchasing.service.impl;

import com.erp.masterdata.material.dao.model.MdMaterial;
import com.erp.masterdata.material.dao.model.MdMaterialCO;
import com.erp.masterdata.material.dao.model.MdMaterialCategory;
import com.erp.masterdata.material.service.MdMaterialCategoryService;
import com.erp.masterdata.material.service.MdMaterialService;
import com.erp.order.purchasing.service.OtherService;
import org.redragon.framework.hibernate.model.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 乱七八糟 业务实现层
 * @Author: syz
 * @blame syz
 * @CreateTime: 2021/4/6
 */
@Service
public class OtherServiceImpl implements OtherService {

    /**
     * 物资服务
     */
    @Lazy
    @Autowired
    private MdMaterialService materialService;

    /**
     * 物资类目服务
     */
    @Lazy
    @Autowired
    private MdMaterialCategoryService mdMaterialCategoryService;


    /**
     * 根据物资类目获取物资集合
     * @param pages 分页对象
     * @param mdMaterial 物资对象
     * @return 物资集合
     */
    @Override
    public List<MdMaterial> getMaterialList(Pages pages, MdMaterialCO mdMaterial) {
        List<MdMaterial> mdMaterialList = materialService.getDataObjects(pages, mdMaterial);
        for(MdMaterial m: mdMaterialList) {
            MdMaterialCategory mdMaterialCategory = mdMaterialCategoryService.getDataObject(m.getCategoryCode());
            if(mdMaterialCategory!=null) {
                m.setCategoryDesc(mdMaterialCategory.getSegmentDesc());
            }
        }
        return mdMaterialList;
    }

}